Modern programming languages such as PASCAL, MESA, and ADA allow computer programmers to specify in their programs the exact range of values that are acceptable for a given variable. For example, a variable denoting the day-of-month may have a specified range from 1 to 31, and values outside of this range will be considered non-allowed values for this variable. Therefore, to meet the specifications of the language, every new assignment of a value to a ranged variable must be checked to ensure that the new value lies within the acceptable range.
The term "value" refers herein to any numerical quantity. It can be represented in various ways, for example as the result of an arithmetic or a logical operation, as the contents of a storage location, as a given constant quantity, or as the state of some device.
The language implementations generally attempt to catch as many "out of range" errors as possible at the time of converting a computer program from the higher level languages in which the program is written to the machine level code which the computer is capable of executing. However, whenever expressions, such as equations for determining the value of a variable, are evolved that must be evaluated during program execution and not during program conversion, extra machine level code must be generated that will cause the computer to check the variable's values during program execution to guarantee that new values are within the specified range. These requirements greatly complicate the operation, and hence the structure, of the compiler, which is a program that carries out the pre-execution conversion of the higher level language program into machine level code. The semantics of these checks vary from language to language and thus the compiler of each language must be differently structured to accommodate the particular semantics. However, a common requirement of range checking is that the expression be evaluated and the results be compared to the range before they are stored in the location assigned to the variable.
Conventional computers make little provision for supporting the range checks. As a result they must perform the checks is software, and the logic sequence that they must follow to perform range checks is fairly complex. In computing a value for a ranged variable, a conventional machine must first allocate a temporary storage space. This is generally a register in the machine's central processing unit, and it may necessitate storing the register's prior contents elsewhere. The machine then performs the computation, and stores the result in the temporary storage space. Next the contents of the temporary storage are compared against the low limit of the range. If the contents are less than the low limit, a branch must be performed to an error handling routine. If the contents are greater than the low limit, the contents of the temporary storage are compared against the high limit of the range. If the contents are greater than the high limit, a branch to an error handling routine must again be performed. Finally, if the contents of the temporary storage lie within the range, the operation is completed by storing the contents of the temporary storage in the location assigned to the variable.
Because the above-described process is complex and because it is done in software, the range checking operation is very slow. Hence it has a high overhead cost associated with it. Especially detrimental to system performance in terms of overhead is the allocation and explicit referencing of the temporary storage of the computed value. Additionally, the software required to perform the range check consumes a great deal of memory storage.
Furthermore, this process does not permit memory-to-memory instructions to be utilized in conjunction with range checking. Memory-to-memory instructions obtain operands from the memory and store results in the memory. The above-described range checking process, however, requires that the calculated result be stored in a temporary location, and be moved to a permanent memory location only after the range check has been performed. Hence the range checking process results in a proliferation of instructions and an underutilization of the capability of many machines, with a resulting increase in system overhead.
A few modern instruction sets, such as the military standard instruction set described in Instruction Set Architecture for the Military Computer Family, MIL-STD-1862 (May 28, 1980), provide a single instruction to test the contents of the temporary storage against the upper and lower limits of the range and to take an exception if the contents are out of range. While this effectively compresses the test-and-branch steps described above into one instruction, the major overhead of allocating the temporary storage and of otherwise specifying its location is unaffected thereby. Furthermore, such an instruction still does not permit memory to memory instructions to be combined with range checking. The advantage achieved with the single instruction is therefore limited.